package com.ruoyi.kong.service.impl;

import com.ruoyi.kong.entity.KongConsumer;
import com.ruoyi.kong.entity.KongEntity;
import com.ruoyi.kong.entity.KongPlugin;
import com.ruoyi.kong.fegin.KongClientService;
import com.ruoyi.kong.service.IKongConsumerService;
import com.ruoyi.kong.utils.KongActiveProfileUtil;
import com.ruoyi.kong.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class KongConsumerServiceImpl implements IKongConsumerService {

    @Autowired
    private KongActiveProfileUtil kongActiveProfileUtil;

    @Override
    public KongEntity<KongConsumer> consumers() {
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).consumers();
    }

    public KongConsumer consumerById(String id){
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).consumerById(id);
    }

    public KongConsumer addConsumer(KongConsumer consumer){
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).addConsumer(consumer);
    }

    public void deleteConsumer(String id){
        KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).deleteConsumer(id);
    }

    public KongConsumer updateConsumer(String id,KongConsumer consumer){
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).updateConsumer(id,consumer);
    }

    public KongEntity<KongPlugin> consumerPlugins(String id){
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).consumerPlugins(id);
    }


    public KongEntity<Map> consumerCredentialByName(String id, String name){
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).consumerCredentialByName(id,name);
    }


    public KongEntity<Map> addConsumerCredential(String id,String name,Map entity){
        Map trimMap = MapUtils.trim(entity);
        return KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).addConsumerCredential(id,name,trimMap);
    }


    public void deleteConsumerCredential(String id,String name,String entityId){
        KongClientService.getInstance(kongActiveProfileUtil.getKongServerUrl()).deleteConsumerCredential(id,name,entityId);
    }
}
